package ru.edu.vstu.atpp.acm.ui.services.dao.impl;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import ru.edu.vstu.atpp.acm.ui.entities.Authors;
import ru.edu.vstu.atpp.acm.ui.services.dao.AuthorsDAO;

import java.util.Collection;

public class AuthorsDAOImpl implements AuthorsDAO {

    @Inject
    Session session;

    @Override
    public Authors findAuthorsByNameAndPassword(String name, String password) {
        Collection<Authors> authorsCollection = session.createCriteria(Authors.class)
                .add(Restrictions.eq("pwd", password))
                .add(Restrictions.eq("name", name)).list();
        return authorsCollection.isEmpty() ? null : authorsCollection.iterator().next();
    }
}
